/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode() : val(0), left(nullptr), right(nullptr) {}
 *     TreeNode(int x) : val(x), left(nullptr), right(nullptr) {}
 *     TreeNode(int x, TreeNode *left, TreeNode *right) : val(x), left(left), right(right) {}
 * };
 */
class Solution {
public:
    TreeNode* invertTree(TreeNode* root) {
        if(root == nullptr)
            return root;
        
        swap(root->left, root->right);

        invertTree(root->left);
        invertTree(root->right);

        return root;
    }

};


class Solution {
public:
    vector<vector<int>> generate(int numRows) {
        vector<vector<int>> result;
        result.resize(numRows);
        for(int i = 0; i < numRows; ++i)
        {
            result[i].resize(i+1,1);
        }
        if(numRows <= 2)
        {
            return result;
        }

        for(int i = 2; i < numRows; ++i)
        {
            for(int j = 1; j < i; ++j)
            {
                result[i][j] = result[i-1][j-1]+result[i-1][j];
            }
        }

        return result;
    }
};


class Solution {
public:
    set<vector<int>> results;
    vector<int> path;

    vector<vector<int>> findSubsequences(vector<int>& nums) {
        dfs(nums, 0);
        vector<vector<int>> ret(results.begin(), results.end());
        return ret;
    }

    void dfs(vector<int>& nums, int start_pos)
    {
        if(path.size() >= 2)
            results.insert(path);

        for(int i = start_pos; i < nums.size(); ++i)
        {
            if(path.empty() || nums[i] >= path.back())
            {
                path.push_back(nums[i]);
                dfs(nums, i+1);
                path.pop_back();
            }
        }
    }
};

